package com.test;

import java.io.IOException;
import java.io.Reader;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.Dao.LiuYanDao;
import com.bean.LiuYanEntity;

public class InsertToLiuYan {

	public static void main(String[] args) {
		String resource="mybatis-config.xml";
		Reader reader=null;
		LiuYanEntity ly=new LiuYanEntity();
		ly.setId(100);
		ly.setUsername("ada");
		ly.setTel(1356483313);
		ly.setEmail("dasdas@qq.com");
		ly.setContent("adadasdsa");
		ly.setTime(1502433557);
		try {
			reader=Resources.getResourceAsReader(resource);
			SqlSessionFactory sessionFactory=new SqlSessionFactoryBuilder().build(reader);
			SqlSession session=sessionFactory.openSession();
			LiuYanDao lydao=session.getMapper(LiuYanDao.class);
			//直接插入，没有返回值,因为此处直接插入UserEntity，所以在xml中#{}中的值直接写UserEntity中的属性
			lydao.insertLiuYan(ly);
			//提交到数据库
			session.commit();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

	}

}
